package com.koron.order.overhaul.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.order.overhaul.bean.entity.OverhaulOrderBean;
import com.koron.order.overhaul.service.OverhaulOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author twcao
 * @title: OverhaulOrderToExecuteController
 * @projectName GDH_EAM_V2
 * @description: 大修工单-待执行
 * @date 2021/10/219:06
 */
@Slf4j
@Api(tags = "大修工单-待执行")
@RestController
@RequestMapping("/overhaul/toExecute")
public class OverhaulOrderToExecuteController {

    @Autowired
    private OverhaulOrderService overhaulOrderService;

    @Deprecated
    @ApiOperation(value = "待执行(status = 2)，新增或修改(提交)，只能修改状态，可反复提交")
    @PostMapping("/saveOrUpdate")
    public Response<Boolean> toExecute(@CasUser @ApiIgnore EamUser user, @RequestBody OverhaulOrderBean bean) {
        log.info("待执行-新增或修改，bean = {}", JSON.toJSONString(bean));
        bean.setDeptId(StringUtils.isBlank(bean.getDeptId()) ? user.getOrgId() : bean.getDeptId());
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), overhaulOrderService, "toExecute", Boolean.class, bean));
    }
}
